<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [12, 0, 0.2, 23, 234, 23, 12, 2, 245, 23, 12, 6787, 986, 4352];

        //从小到大 排序 sort
        // 方法1
        var newSort = arr.sort(function(a, b) {
            return b - a;
        });

        // 方法2 内层循环 两两比较
        for (var i = 0; i < arr.length - 1; i++) {
            //外层循环控制轮数
            for (var j = 0; j < arr.length - 1 - i; j++) {
                //内层循环控制轮数 每轮确定几个人就会少比几次
                if (arr[j] > arr[j + 1]) {
                    var temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        //方法3：选择排序
        //外层循环 和 内存循环 相比较
        for (var i = 0; i < arr.length - 1; i++) {
            for (var j = i + 1; j < arr.length; j++) {
                if (arr[j] > arr[i]) {
                    var temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        console.log(arr);
    </script>
</body>

</html>